#include "project.h"
#include "document.h"
#include "word.h"
using namespace TA;

Project::Project(QObject *parent) : QObject(parent)
{

}

Project::Project(QObject *parent, const QString &uuid):QObject(parent)
{
    this->uuid = uuid;
}

QString Project::getUuid() const
{
    return uuid;
}

void Project::setUuid(const QString &value)
{
    uuid = value;
}

QDate Project::getCreateDate() const
{
    return createDate;
}

void Project::setCreateDate(const QDate &value)
{
    createDate = value;
}

QString Project::getProjectTitle() const
{
    return projectTitle;
}

void Project::setProjectTitle(const QString &value)
{
    projectTitle = value;
}

bool Project::getDeleted() const
{
    return deleted;
}

void Project::setDeleted(bool value)
{
    deleted = value;
}

DocumentRawPtrArray* Project::getDocuments() const
{
    return (DocumentRawPtrArray*)&documents;
}

void Project::setDocuments(const DocumentRawPtrArray * value)
{
    documents = *value;
}

WordRawPtrArray* Project::getWords() const
{
    return (WordRawPtrArray* )&words;
}

void Project::setWords(const WordRawPtrArray *value)
{
    words = *value;
}

bool Project::hasDocument(Document *doc)
{
    bool result = false;
    for(auto it = this->documents.begin();it!=this->documents.end();it++){
        if(*doc == **it){
            result = true;
            break;
        }
    }

    return result;
}

bool Project::operator==(const Project &rhs)
{
    return this->uuid == rhs.uuid;
}

bool Project::operator!=(const Project &rhs)
{
    return this->uuid != rhs.uuid;
}

Document* Project::findDocument(const QString &title) {
    Document* result = nullptr;

    for (auto it = this->documents.begin(); it != this->documents.end() ; ++it) {
        if ( title == (*it)->getTitle() ){
            result = (*it);
            break;
        }
    }
    return result;
}

Word* Project::findWord(const QString &word) {
    Word* result = nullptr;

    for (auto it = this->words.begin(); it != words.end() ; ++it) {
        if (word == (*it)->getWord() ){
            result = (*it);
            break;
        }
    }

    return result;
}

WordGroupRawPtrArray* Project::getGroups() const {
    return (WordGroupRawPtrArray*)&groups;
}

void Project::setGroups(const WordGroupRawPtrArray &groups) {
    Project::groups = groups;
}

